{include file="public/head"}
<style>
    .m-cell {
        background-color: #FFF;
        position: relative;
        z-index: 1;
        margin-bottom: .35rem;
        height: 3rem;
        line-height: 3rem;
    }

    .title{
        font-size: 1.2rem;
        margin-bottom: .4rem;
        color: silver;
    }
</style>
<body style="background:#eee">

<header class="aui-header-default aui-header-fixed aui-header-bg">
    <a href="javascript:history.back(-1)" class="aui-header-item">
        <i class="aui-icon aui-icon-back-white"></i>
    </a>
    <div class="aui-header-center aui-header-center-clear">
        <div class="aui-header-center-logo">
            <div class="aui-car-white-Typeface" style="color:black;font-weight: bold;">提现信息</div>
        </div>
    </div>
    <a href="#" class="aui-header-item-icon"   style="min-width:0">
        <!--<i class="aui-icon aui-icon-search"></i>-->
    </a>
</header>


<section class="aui-myOrder-content">
    <div class="aui-prompt"><i class="aui-icon aui-prompt-sm"></i>填写您的提现信息</div>
    <div class="aui-Address-box">
        <div class="title">银行信息</div>
        <p>
            <input class="aui-Address-box-input" type="text" id="bank_name"  value="{$BankInfo.bank_name}" placeholder="开户银行">
        </p>
        <p>
            <input class="aui-Address-box-input" type="text" id="bank_open"  value="{$BankInfo.bank_open}" placeholder="开户支行">
        </p>

        <p>
            <input class="aui-Address-box-input" type="text" id="bank_num"  value="{$BankInfo.bank_num}" placeholder="银行卡号">
        </p>

        <p>
            <input class="aui-Address-box-input" type="text" id="bank_user" value="{$BankInfo.bank_user}" placeholder="开户姓名">
        </p>

        <div class="title">微信收款码</div>
        <p style="background: white;height: 12rem;padding-top: 2rem">
            <label for="wechat_code">
                <img id="wechat_code_url" src="{$BankInfo.wechat_code}" onerror="this.src='__STATIC__/User/img/icon/upLoad.png'" style="width: 8rem;margin: auto">
                <input type="file" id="wechat_code" class="upload_pic" style="display: none;">
            </label>
        </p>

        <div class="title">支付宝收款码</div>
        <p style="background: white;height: 12rem;padding-top: 2rem">
            <label for="ali_code">
                <img id="ali_code_url" src="{$BankInfo.ali_code}" onerror="this.src='__STATIC__/User/img/icon/upLoad.png'" style="width: 8rem;margin: auto">
                <input type="file" id="ali_code" class="upload_pic" style="display: none;">
            </label>
        </p>


    </div>
    <div class="aui-out">
        <a href="javascript:" class="red-color" style="color:#fff" id="add">保存并使用</a>
    </div>
</section>


<script type="text/javascript" src="__STATIC__/User/js/jquery.min.js"></script>
<script>
    //ajax异步图片上传
    $('.upload_pic').change(function(){
        //图片对象
        let that = $(this);
        var formData = new FormData();
        formData.append("image", that[0].files[0]);

        // 上传设置
        $.ajax({
            // 规定把请求发送到那个URL
            url: "{:url('User/forUpload')}",
            type: "post",            // 请求方式
            dtaType: 'json',
            data: formData,//传值就传fd对象了
            processData:false,  //告诉jQuery不要处理数据
            contentType: false,  //告诉jQuery不要设置contentType
            // 请求成功时执行的回调函数
            success: function (data) {
                if(data.status == 1)
                {
                    that.prev().attr('src',data.message);
                }
                else
                {
                    alert(data.message);
                }
            }
        });
    });


    //保存操作
    $('#add').on('click',function () {
        var bank_name = $('#bank_name').val();
        var bank_open = $('#bank_open').val();
        var bank_num = $('#bank_num').val();
        var bank_user = $('#bank_user').val();
        var wechat_code_url = $('#wechat_code_url').attr('src');
        var ali_code_url = $('#ali_code_url').attr('src');
        if(wechat_code_url == '/static/User/img/icon/upLoad.png'){
            var wechat_code = '';
        }else{
            var wechat_code = wechat_code_url;
        }

        if(ali_code_url == '/static/User/img/icon/upLoad.png'){
            var ali_code = '';
        }else{
            var ali_code = ali_code_url;
        }

        $.ajax({
            type:"POST",
            url:"{:url('User/UserBank')}",
            data:{
                bank_name:bank_name,
                bank_open:bank_open,
                bank_num:bank_num,
                bank_user:bank_user,
                wechat_code:wechat_code,
                ali_code:ali_code,
            },
            dataType:"json",
            success:function(data){
                if(data.status == 1){
                    alert(data.message);
                    window.location.reload();
                }else{
                    alert(data.message);
                }
            }
        })
    })
</script>

</body>
</html>